﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace XclusiveService.Models
{
    public class EmployeeRepository : IEmployeeRepository
    {
        //Getting all the Employees
        public IEnumerable<Employee> GetAllEmployees()
        {
            return DatabaseManager.GetAllEmployees().Cast<Employee>();
        }

        //Getting the Employees by company_name
        public IEnumerable<Employee> GetEmployeesByCompanyName(string company_name)
        {
            return DatabaseManager.GetEmployeesByCompanyName(company_name).Cast<Employee>();
        }

        //Getting an Employee by employeeID
        public Employee GetEmployeeByEmployeeID(int employeeID)
        {
            return DatabaseManager.GetEmployeeByEmployeeID(employeeID);
        }

        //Creating an Employee (POST)
        public Employee CreateEmployee(Employee emp)
        {
            if (emp == null)
            {
                throw new ArgumentNullException("emp");
            }

            if (DatabaseManager.CreateEmployee(emp) == 0)
            {
                return null;
            }
            else
            {
                return emp;
            }
        }

        //Updating an Employee (PUT)
        public bool UpdateEmployee(Employee emp)
        {
            if (emp == null)
            {
                throw new ArgumentNullException("emp");
            }

            if (DatabaseManager.UpdateEmployee(emp) == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        //Deleting an Employee by EmployeeID
        public void DeleteEmployeeByEmployeeID(int employeeID)
        {
            DatabaseManager.DeleteEmployeeByEmployeeID(employeeID);
        }

        //Deleting the employees by company_name
        public void DeleteEmployeeByCompanyName(int company_name)
        {
            DatabaseManager.DeleteEmployeeByCompanyName(company_name);
        }
    }
}